package com.turing.usdtpay.mvp.view.popwindow;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.PopupWindow;

/**
 * Created by $Jay
 * Date : 2019\2\22 0022
 **/
public abstract class CommonPopupWindow {
    protected Context mContext;
    protected View mContentView;
    protected PopupWindow mInstance;

    public CommonPopupWindow(Context context, int layoutRes, int width, int height) {
        mContext = context;
        mContentView = LayoutInflater.from(context).inflate(layoutRes, null, false);
        initView();
        mInstance = new PopupWindow(mContentView, width, height);
        initWindow();
    }

    private void initWindow() {
        mInstance.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
        mInstance.setTouchable(true);
        mInstance.setOutsideTouchable(true);
    }

    protected abstract void initView();

    public View getContentView() {
        return mContentView;
    }

    public PopupWindow getPopupWindow() {
        return mInstance;
    }


    public void showAsDropDown(View anchor, int xoff, int yoff) {
        mInstance.showAsDropDown(anchor, xoff, yoff);
    }

    public void showAsDropDown(View anchor) {
        mInstance.showAsDropDown(anchor, 0, 0);
    }

    public void showAtLocation(View parent, int gravity, int x, int y) {
        mInstance.showAtLocation(parent, gravity, x, y);
    }

}
